package main

import (
	"context"
	"fmt"

	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/consumer"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"github.com/apache/rocketmq-client-go/v2/rlog"
)

func main() {
	nameServer, err := primitive.NewNamesrvAddr("29.2.198.24:9876")
	if err != nil {
		panic(err)
	}
	rlog.SetLogLevel("warn")

	c, err := rocketmq.NewPushConsumer(
		consumer.WithNameServer(nameServer),
		consumer.WithGroupName("test-go-groupName"),
	)
	if err != nil {
		panic(err)
	}
	err = c.Subscribe("UFEP-TASK-MSG", consumer.MessageSelector{
		Type:       consumer.TAG,
		Expression: "goLangTag",
	},
		func(ctx context.Context, mes ...*primitive.MessageExt) (consumer.ConsumeResult, error) {
			for _, me := range mes {
				fmt.Printf("consumer message: %s\n", string(me.Body))
			}
			return consumer.ConsumeSuccess, nil
		})
	if err != nil {
		panic(err)
	}
	c.Start()
	defer c.Shutdown()

	select {}
}
